﻿using System;
using System.Linq;
using System.Xml.Serialization;
using mmCore.Common;

namespace mmCore.Classes
{
    [Serializable]
    public class Movie: NotifyPropertyChangedBase
    {
        #region MEMBERS
        [XmlIgnore]
        private string _mTitle;
        [XmlIgnore]
        private string _mId;
        [XmlIgnore]
        private int _mSeason;
        [XmlIgnore]
        private int _mSeasonCount;
        [XmlIgnore]
        private string _mCoverWeb;
        [XmlIgnore]
        private string _mCoverLocal;
        [XmlIgnore]
        private SObservableCollection<Episode> _mEpisodes;
        [XmlIgnore] 
        private bool _mReloading;
        #endregion MEMBERS

        public string Title
        {
            set 
            { 
                _mTitle = value;
                RaisePropertyChanged(() => Title);
            }
            get { return _mTitle; }
        }
        public string Id
        {
            set
            {
                _mId = value;
                RaisePropertyChanged(() => Id);
            }
            get { return _mId; }
        }
        public int Season
        {
            set
            {
                _mSeason = value;
                RaisePropertyChanged(() => Season);
                RaisePropertyChanged(() => NotSeenTilToday);
            }
            get { return _mSeason; }
        }
        public int SeasonCount
        {
            set
            {
                _mSeasonCount = value;
                RaisePropertyChanged(() => SeasonCount);
            }
            get { return _mSeasonCount; }
        }
        public string CoverWeb
        {
            set
            {
                _mCoverWeb = value;
                RaisePropertyChanged(() => CoverWeb);
            }
            get { return _mCoverWeb; }
        }
        public string CoverLocal
        {
            set
            {
                _mCoverLocal = value;
                RaisePropertyChanged(() => CoverLocal);
            }
            get { return _mCoverLocal; }
        }

        public SObservableCollection<Episode> Episodes 
        { 
            set 
            { 
                _mEpisodes = value;
                RaisePropertyChanged(() => Episodes);
            }
            get { return _mEpisodes; } 
        }

        [XmlIgnore]
        public bool Reloading
        {
            get { return _mReloading; }
            set
            {
                _mReloading = value;
                RaisePropertyChanged(() => Reloading);
            }
        }

        [XmlIgnore]
        public int NotSeenTilToday
        {
            get
            {
                if(Episodes == null || Episodes.Count == 0)
                {
                    return 0;
                }

                return Episodes.ToList().Where(
                    ep =>
                    ep.AirDate != DateTime.MinValue && ep.AirDate <= DateTime.Today && ep.Seen == false &&
                    ep.Season == Season).Count();
            }

            set
            {
                RaisePropertyChanged(() => NotSeenTilToday);
            }
        }
    }
}
